#include "progressbar.h"
#include <string.h>
#include <unistd.h>

#define SIZE 101
#define TYPE '#'



void progressbar2(double total, double current)
{
    char buffer[SIZE];
    memset(buffer,0,SIZE);
    const char* lable = "- ";
    int len = strlen(lable);

    double num = current*100/total;
    int i = 0;
    for(i=0; i<(int)num; ++i)
    {
        buffer[i] = TYPE;
    }
    
    static int cnt = 0;
    cnt %= len;
    printf("[%-100s][%.1f\%][%c]\r",buffer,num,lable[cnt]);
    cnt++;
}



void progressbar1()
{
    char buffer[SIZE];
    memset(buffer,0,SIZE);
    const char* lable = "|/-\\";
    int len = strlen(lable);

    int cnt = 0;
    while(cnt <= 100)
    {
        printf("[%-100s][%d\%][%c]\r",buffer,cnt,lable[cnt%len]);
        fflush(stdout);
        usleep(100000);
        buffer[cnt] = TYPE;
        cnt++;
    }
    printf("\n");
}

